package com.dodayum.java8.pattern.strategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author BaiYu
 * @date 2023/11/2415:27
 */
public class Select {

    public static final String planA = "A";
    public static final String planB = "B";
    private static final Map<String,IStrategy> selectMap = new HashMap<>();
    {
        selectMap.put(planA,new ConcreteStrategyA());
        selectMap.put(planB,new ConcreteStrategyB());
        System.out.println("数据已添加完成");
    }

    public IStrategy getIStrategy(String key){
        IStrategy iStrategy = selectMap.get(key);
        if (iStrategy == null){
            throw new RuntimeException("策略查询失败");
        }
        return iStrategy;
    }
}
